package com.spike.servlet;

import com.spike.model.Dept;
import com.spike.service.DeptService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findByNA")
public class FindByNAServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String name = req.getParameter("name");
        String address = req.getParameter("address");
        Dept dept = new Dept();
        dept.setName(name);
        dept.setAddress(address);
        DeptService deptService = new DeptService();
        try {
            List<Dept> byNA = deptService.findByNA(dept);
            req.setAttribute("deptList", byNA);
            req.setAttribute("name",name);
            req.setAttribute("address",address);
            req.getRequestDispatcher("WEB-INF/jsp/deptList.jsp").forward(req, resp);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
